package recursionstu

import (
	"fmt"
	"io/ioutil"
	"log"
	"path/filepath"
)

//递归
func Add(n int) int {
	if n <= 1 {
		fmt.Printf("%v=", n)
		return 1
	}
	fmt.Printf("%v+", n)
	return n + Add(n-1)
}

//递归 斐波拉契数
//1,1,2,3,5,8,13,21,34,55,89......
//n=1或n=2时都是1
//n>2 时，An=A(n-1)+A(n-2);
func Fibora(n int) int {
	if n <= 2 {
		return 1
	}
	return Fibora(n-1) + Fibora(n-2)
}

//递归打印文件目录
//如果是文件 打印名称
//如果是文件夹打印名称递归
func FileTree(path string) {

	fs, err := ioutil.ReadDir(path)
	if err != nil {
		log.Fatal("失败", err)
	}
	for _, file := range fs {
		if !file.IsDir() {
			fmt.Println("文件:", filepath.Join(path, file.Name()))
		} else {
			path = filepath.Join(path, file.Name())
			fmt.Println("目录:", path)
			FileTree(path)
		}
	}

}
